<?php

function VerifyEmail($email){
	$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
	$cn = false;
	if( !($host = strstr($email, "@")) ){
		return -1;	
	}
	
	$host = substr($host, 1);
	if( !getmxrr($host, $mxs) ){
		return -1;	
	}
	
	foreach($mxs as $m){
		if( socket_connect($sock, "mx1.qq.com", 25) ){
			$cn = true;
			break;
		}
	}
	
	if(false == $cn){
		return -1;	
	}

	$recv = "";
	if( !socket_recv($sock, $recv, 1024, 0) ){
		return -1;
	}

	if(220 != $recv){
		return -1;
	}

	$sends = array("HELO verify-email.org\r\n", 
		"MAIL FROM: <check@verify-email.org>\r\n",
		"RCPT TO: <{$email}>\r\n");
	foreach($sends as $s){
		if( !socket_send($sock, $s, strlen($s), 0) ){
			return -1;	
		}
		
		$recv = "";
		if( !socket_recv($sock, $recv, 1024, 0) ){
			return -1;	
		}
		
		if( 220 != $recv && 250 != $recv ){
			return 1;	
		}
	}

	socket_close($sock);
	return 0;
}

echo VerifyEmail("914910235@qq.com");
?>

